﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace ClipboardTranslator
{
    public class DesktopToolTip
    {
        static Form form = null;
        class Form : System.Windows.Forms.Form
        {
            string text;
            string title;
            ToolTipIcon icon;
            int duration;
            ToolTip tooltip;

            public Form(string text, string title, ToolTipIcon icon, int x, int y, int duration)
            {
                if (null != form)
                {
                    form.tooltip.Hide(form);
                    form.Close();
                }
                this.text = text;
                this.title = title;
                this.icon = icon;
                this.duration = duration;
                FormBorderStyle = FormBorderStyle.None;
                StartPosition = FormStartPosition.Manual;
                ShowInTaskbar = false;
                Left = x;
                Top = y;
                Width = 1;
                Height = 1;
                TransparencyKey = BackColor;
                TopMost = true;
                Shown += new EventHandler(Form_Shown);
                form = this;
            }

            void Form_Shown(object sender, EventArgs e)
            {
                tooltip = new ToolTip();
                tooltip.ToolTipTitle = title;
                tooltip.ToolTipIcon = icon;
                tooltip.Show(text, this, 0, 0, duration);
            }
        }

        public static void Show(string text, int duration)
        {
            Show(text, Cursor.Position, duration);
        }

        public static void Show(string text, string title, int duration)
        {
            Show(text, title, Cursor.Position, duration);
        }

        public static void Show(string text, string title, ToolTipIcon icon, int duration)
        {
            Show(text, title, icon, Cursor.Position, duration);
        }

        public static void Show(string text, Point location, int duration)
        {
            Show(text, location.X, location.Y, duration);
        }

        public static void Show(string text, string title, Point location, int duration)
        {
            Show(text, title, location.X, location.Y, duration);
        }

        public static void Show(string text, string title, ToolTipIcon icon, Point location, int duration)
        {
            Show(text, title, icon, location.X, location.Y, duration);
        }

        public static void Show(string text, int x, int y, int duration)
        {
            Show(text, null, x, y, duration);
        }

        public static void Show(string text, string title, int x, int y, int duration)
        {
            Show(text, title, ToolTipIcon.None, x, y, duration);
        }

        public static void Show(string text, string title, ToolTipIcon icon, int x, int y, int duration)
        {
            new Form(text, title, icon, x, y, duration).Show();
        }
    }
}
